## This file replicates the figures and tables in Chapters 2 and 3 of:
## Sharan Grewal, Soldiers of Democracy? Military Legacies and
## the Arab Spring, Oxford University Press, 2023.
## For any questions, contact: ssgrewal@wm.edu


############################
## Load packages and data ##
############################

library(survival)
library(cmprsk)
library(effects)
library(ggplot2)
library(stargazer)
library(contsurvplot) #devtools::install_github("RobinDenz1/contsurvplot")
library(pammtools)

data <- read.csv("data.csv")



###############
## Chapter 2 ##
###############


## Figure 2.1: Predicted Coup Risk in Dictatorships by Military Expenditure, 1946-2010

one <- coxph(Surv(gwf_case_duration, event=coup_success)~budgetNA_100_lag+budgetNA_100_lag_sq, data=data)

newdata <- data.frame(budgetNA_100_lag=seq(min(data$budgetNA_100_lag, na.rm=T), 42, by=1), budgetNA_100_lag_sq=(seq(min(data$budgetNA_100_lag, na.rm=T), 42, by=1)*seq(min(data$budgetNA_100_lag, na.rm=T), 42, by=1)))

plot(predict(one, data.frame(newdata), interval="confidence", type="risk"), ylab="Coup Risk", xlab="Military Spending as Percent of Total Budget (CNTS)", main="Dictator's Coup Risk by Military Expenditure", xaxt="n")
axis(1, 1:43, seq(min(data$budgetNA_100_lag, na.rm=T), 42, by=1))


## Figure 2.2: Military Ministers in Dictatorships by Military Expenditure, 1946-2010

two <- lm((ministers100)~budgetNA_100, data=data[data$gwf_case_duration>0,])
plot(effect("budgetNA_100", two), main="Ministers and Military Expenditure in Dictatorships", xlab="Military Spending as Percent of Total Budget (CNTS)", ylab="Military Percent of Cabinet (White)", colors="black", band.colors="grey0")



## Figure 2.3: Counterbalancing in Dictatorships by Military Expenditure, 1946-2010

three <- lm(counterbalancing~budgetNA_100, data=data)
plot(effect("budgetNA_100", three), main="Counterbalancing and Military Expenditure in Dictatorships", xlab="Military Spending as Percent of Total Budget (CNTS)", ylab="Counterbalancing (GWF)", colors="black", band.colors="grey0")




## Figure 2.4: In-Group Stacking in Dictatorships by Military Expenditure, 1946-2010

four <- lm(stacking~budgetNA_100, data=data)
plot(effect("budgetNA_100", four), main="Stacking and Military Expenditure in Dictatorships", xlab="Military Spending as Percent of Total Budget (CNTS)", ylab="Stacking (GWF)", colors="black", band.colors="grey0")






###############
## Chapter 3 ##
###############


## Figure 3.1: Histogram of Military Expenditure in Dictatorships, 1946-2010

hist(data$avbudget100[!is.na(data$gwf_case_duration)], xlab="Percent of Total Budget (CNTS)", main="Average Military Expenditure in Dictatorships", freq=F)



## Figure 3.2: Predicted Coup Risk in Dictatorships by Coup-Proofing Strategy, 1946-2010
## (same figure as Figure 2.1)




## Table 3.1: Dictator's Coup Risk (Cox Proportional Hazards)

one <- coxph(Surv(gwf_case_duration, event=coup_success)~budgetNA_lag_std+budgetNA_lag_sq_std, data=data)

two <- coxph(Surv(gwf_case_duration, event=coup_success)~budgetNA_lag_std+budgetNA_lag_sq_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data)

three <- coxph(Surv(gwf_case_duration, event=coup_success)~budgetNA_lag_std+budgetNA_lag_sq_std+counterbalancing_lag+stacking_lag+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data)


four <- coxph(Surv(gwf_case_duration, event=coup_success)~ministers_lag+ministers_lag_sq, data=data)

five <- coxph(Surv(gwf_case_duration, event=coup_success)~ministers_lag+ministers_lag_sq+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data)

six <- coxph(Surv(gwf_case_duration, event=coup_success)~ministers_lag+ministers_lag_sq+counterbalancing_lag+stacking_lag+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data)


stargazer(one, two, three, four, five, six, single.row=T, digits=1, covariate.labels=c("Military Budget","Military Budget$^2$","Counterbalancing","Stacking","Civil War","Foreign War","Coup-Born","Rebel-Born","Military Regime","Personalist Regime","Conscription","Population, log","GDP per capita, log","Delta GDP per capita","Oil Production, log","Education, log","% Protestant","% Muslim","Post-Cold War","Military Ministers","Military Ministers$^2$"))






#######################
# Choice of Strategy ##
#######################


## Figure 3.3: Choice of Coup-Proofing Strategy in Dictatorships, 1946-2010

one <- lm(budgetNA_100~coup_fail_lag+couplagregion_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data[data$gwf_case_duration>0,])

coef <- as.data.frame(rbind(summary(one)$coef[2:9,1:2]))
colnames(coef) <- c("mean", "se")
coef$name <- c("Failed Coup","Coup in Region","Civil War","Foreign War","Coup-Born","Rebel-Born","Military Regime","Personalist Regime")
coef$name <- factor(coef$name, levels=rev(c("Failed Coup","Coup in Region","Civil War","Foreign War","Coup-Born","Rebel-Born","Military Regime","Personalist Regime")))

ggplot(coef, aes(x=mean, y=name)) +
       geom_point(stat="identity", position="identity") +
       geom_errorbarh(aes(xmin=mean-1.96*se, 
                    xmax=mean+1.96*se, height=0.5), size=0.2) +
  geom_vline(aes(xintercept=0)) +
  ggtitle("Choice of Strategy") +
  theme_bw() + 
  theme(panel.grid.major = element_blank()) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  xlab("Military Expenditure (% Budget) ") +
  ylab("") +
  scale_x_continuous(limits=c(-6, 12),breaks=seq(-5, 10, by=5)) +
  theme(text = element_text(size=17))



## Table 3.2: Dictator's Choice of Coup-Proofing Strategy (OLS)

one <- lm(budgetNA~coup_fail_lag+couplagregion_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data[data$gwf_case_duration>0,])

two <- lm(budgetNA~budgetNA_lag_std+coup_fail_lag+couplagregion_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data[data$gwf_case_duration>0,])

three <- lm(budgetNA~budgetNA_lag_std, data=data[data$gwf_case_duration>0,])

four <- lm(ministers~coup_fail_lag+couplagregion_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data[data$gwf_case_duration>0,])

five <- lm(ministers~ministers_lag+coup_fail_lag+couplagregion_std+civilwar_lag+war_lag+seizure_coup+seizure_rebel+gwf_military+gwf_personal+conscript+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_primsec_std+PRTPC10+MUSPC10+post90, data=data[data$gwf_case_duration>0,])

six <- lm(ministers~ministers_lag, data=data[data$gwf_case_duration>0,])


stargazer(one, two, three, four, five, six, single.row=T, digits=2, covariate.labels=c("Budget last year","Ministers last year","Failed Coup","Coup in Region","Civil War","Foreign War","Coup-Born","Rebel-Born","Military Regime","Personalist Regime","Conscription","Population, log","GDP per capita, log","Delta GDP per capita","Oil Production, log","Education, log","% Protestant","% Muslim","Post-Cold War"))





###########
## NAVCO ##
###########

navco <- read.csv("NAVCO2-1_ForPublication.csv") # https://navcomap.wcfia.harvard.edu/dataverse
navco$ccode <- navco$loc_cow

navco <- merge(navco, data[c("ccode","year","budgetNA_100","budgetNA_std","gwf_military_lag","conscript","counterbalancing","stacking","log_GDP_pc_lag_std","ch_economics2_log_lag_std","log_population_std","PRTPC10","MUSPC10","log_oil_std","log_primsec_std")], by=c("ccode","year"), all.x=T)

navco <- navco[navco$camp_goals==0,]

navco$logsize_std <- (log(navco$total_part)-min(log(navco$total_part), na.rm=T))/(max(log(navco$total_part), na.rm=T)-min(log(navco$total_part), na.rm=T))

navco$united <- ifelse(navco$camp_confl_intensity<2, 1, 0)


## Table 3.3: Coup-Proofing Strategy and Repression of Mass Uprisings (NAVCO)

one <- lm((repression>1)~budgetNA_std, data=navco)

two <- lm((repression>1)~budgetNA_std+gwf_military_lag+conscript+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

three <- lm((repression>1)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

four <- lm((indiscrim==1)~budgetNA_std, data=navco)

five <- lm((indiscrim==1)~budgetNA_std+gwf_military_lag+conscript++(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

six <- lm((indiscrim==1)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

stargazer(one, two, three, four, five, six, single.row=T, digits=2, covariate.labels=c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","End Year of Campaign","Nonviolent","Campaign Size, log","Hierarchal","United","Ideological Diversity","Class Diversity","Gender Diversity","Foreign Support","Diaspora Support","Foreign Media","Domestic Media","Reliability","Population, log","GDP per capita, log","Delta GDP per capita","Oil Production, log","Education, log","% Protestant","% Muslim"))



## Figure 3.4: Indiscrimination Repression of Mass Uprisings, 1946-2010 (NAVCO)

## A: Effect Plot

one <- lm(((indiscrim==1)*100)~budgetNA_100, data=navco)

plot(effect("budgetNA_100", one), main="Indiscriminate Repression of Mass Uprisings (NAVCO)", xlab="Military Spending as Percent of Total Budget (CNTS)", ylab="Repression (%)", colors="black", band.colors="grey0")


## B: Coefficient plot

two <- lm(((indiscrim==1)*100)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)


summary(two)

coef <- as.data.frame(rbind(summary(two)$coef[c(2:6,8:9,11,17),1:2]))
colnames(coef) <- c("mean", "se")
coef$name <- c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","Nonviolent","Size","United","Foreign Media")
coef$name <- factor(coef$name, levels=rev(c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","Nonviolent","Size","United","Foreign Media")))

ggplot(coef, aes(x=mean, y=name)) +
  geom_point(stat="identity", position="identity") +
  geom_errorbarh(aes(xmin=mean-1.96*se, 
                     xmax=mean+1.96*se, height=0.5), size=0.2) +
  geom_vline(aes(xintercept=0)) +
  ggtitle("Indiscriminate Repression") +
  theme_bw() + 
  theme(panel.grid.major = element_blank()) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  xlab("Repression") +
  ylab("") +
  scale_x_continuous(limits=c(-40, 100),breaks=seq(-40, 100, by=20)) +
  theme(text = element_text(size=17))





## Table 3.4: Security Force Defections and the Success of Mass Uprisings (NAVCO)

one <- lm((sec_defect==1)~budgetNA_std, data=navco)

two <- lm((sec_defect==1)~budgetNA_std+gwf_military_lag+conscript+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

three <- lm((sec_defect==1)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

four <- lm((success)~budgetNA_std, data=navco)

five <- lm((success)~budgetNA_std+gwf_military_lag+conscript+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

six <- lm((success)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

stargazer(one, two, three, four, five, six, single.row=T, digits=2, covariate.labels=c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","End of Campaign","Nonviolent","Campaign Size, log","Hierarchal","United","Ideological Diversity","Class Diversity","Gender Diversity","Foreign Support","Diaspora Support","Foreign Media","Domestic Media","Reliability","Population, log","GDP per capita, log","Delta GDP per capita","Oil Production, log","Education, log","% Protestant","% Muslim"))





## Figure 3.5: Success of Mass Uprisings, 1946-2010 (NAVCO)

## A: Effect Plot
one <- lm((success*100)~budgetNA_100, data=navco)

plot(effect("budgetNA_100", one), main="Mass Uprising Succeeds (NAVCO)", xlab="Military Spending as Percent of Total Budget (CNTS)", ylab="Success (%)", colors="black", band.colors="grey0")


## B: Coefficient Plot

two <- lm((success*100)~budgetNA_std+gwf_military_lag+conscript+counterbalancing+stacking+(cyear==2)+prim_meth+logsize_std+camp_structure+united+div_ideology+div_class+div_gender+camp_support+dias_support+in_media+dom_media+(reliability==1)+log_population_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_primsec_std+log_oil_std+PRTPC10+MUSPC10, data=navco)

coef <- as.data.frame(rbind(summary(two)$coef[c(2:6,8:9,11,17),1:2]))
colnames(coef) <- c("mean", "se")
coef$name <- c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","Nonviolent","Size","United","Foreign Media")
coef$name <- factor(coef$name, levels=rev(c("Military Budget","Military Regime","Conscription","Counterbalancing","Stacking","Nonviolent","Size","United","Foreign Media")))

ggplot(coef, aes(x=mean, y=name)) +
  geom_point(stat="identity", position="identity") +
  geom_errorbarh(aes(xmin=mean-1.96*se, 
                     xmax=mean+1.96*se, height=0.5), size=0.2) +
  geom_vline(aes(xintercept=0)) +
  ggtitle("Mass Uprising Succeeds") +
  theme_bw() + 
  theme(panel.grid.major = element_blank()) + 
  theme(plot.title = element_text(hjust = 0.5)) +
  xlab("Success") +
  ylab("") +
  scale_x_continuous(limits=c(-35, 60),breaks=seq(-30, 60, by=30)) +
  theme(text = element_text(size=17))






################
## TRANSITION ##
################


## Table 3.5: Likelihood of Democratic Breakdown (Cox Proportional Hazards)

one <- coxph(Surv(rgjdurd, event=breakdown)~avbudgetpre_ulf_std+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+rgjtdat+pres_lag+domestic8_lag+post90+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data, x=TRUE)

two <- crr(ftime=data$rgjdurd, fstatus=data$rgjatype2, cov1=data[,c("avbudgetpre_ulf_std","log_GDP_pc_lag_std","ch_economics2_log_lag_std","log_oil_std","log_population_std","log_primsec_std","PRTPC10","MUSPC10","post90","rgjtdat","BRITISHCOLONY","avpolitylagregion_std","couplagregion_std","pres_lag","domestic8_lag","gwf_prior_personal","gwf_prior_military","counterbalancing_pre_ulf","stacking_pre_ulf")], failcode="1", cencode="1", na.action=na.omit, maxiter=17)

three <- crr(ftime=data$rgjdurd, fstatus=data$rgjatype3, cov1=data[,c("avbudgetpre_ulf_std","log_GDP_pc_lag_std","ch_economics2_log_lag_std","log_oil_std","log_population_std","log_primsec_std","PRTPC10","MUSPC10","post90","rgjtdat","BRITISHCOLONY","avpolitylagregion_std","couplagregion_std","pres_lag","domestic8_lag","gwf_prior_personal","gwf_prior_military","counterbalancing_pre_ulf","stacking_pre_ulf")], failcode="2", cencode="1", na.action=na.omit, maxiter=17)

four <- crr(ftime=data$rgjdurd, fstatus=data$rgjatype4, cov1=data[,c("avbudgetpre_ulf_std","log_GDP_pc_lag_std","ch_economics2_log_lag_std","log_oil_std","log_population_std","log_primsec_std","PRTPC10","MUSPC10","post90","rgjtdat","BRITISHCOLONY","avpolitylagregion_std","couplagregion_std","pres_lag","domestic8_lag","gwf_prior_personal","gwf_prior_military","counterbalancing_pre_ulf","stacking_pre_ulf")], failcode="2", cencode="1", na.action=na.omit, maxiter=15)


stargazer(one, one, one, one,
          coef=cbind(as.data.frame(summary(one)[7])[1], as.data.frame(summary(two)[6])[1], as.data.frame(summary(three)[6])[1], as.data.frame(summary(four)[6])[1]),
          se=cbind(as.data.frame(summary(one)[7])[3], as.data.frame(summary(two)[6])[3], as.data.frame(summary(three)[6])[3], as.data.frame(summary(four)[6])[3]),
          p=cbind(as.data.frame(summary(one)[7])[5], as.data.frame(summary(two)[6])[5], as.data.frame(summary(three)[6])[5], as.data.frame(summary(four)[6])[5]),
          digits=2, covariate.labels=c("Prev Military Budget","GDP per capita","Ch. GDP per capita","Oil Production","Population","Education","% Protestant","% Muslim","Post-Cold War","Prior Demo Attempts","Former British Colony","Av Polity in Region","Coup in Region","Presidential System","Anti-Gov Protests","Prev Personal Regime","Prev Military Regime","Prev Counterbalancing","Prev Stacking"), single.row=T)

two$loglik
three$loglik
four$loglik


## Figure 3.6: Military Empowerment and Democratic Breakdown, 1946-2010

one <- coxph(Surv(rgjdurd, event=breakdown)~avbudgetpre_ulf_round+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+rgjtdat+pres_lag+domestic8_lag+post90+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data, x=TRUE)

plot_surv_area(time="rgjdurd", status="breakdown", variable="avbudgetpre_ulf_round", data=data, model=one, discrete=TRUE, bins=5, start_color="lightgrey", end_color="black", legend.title ="Av. % of Budget", title="Democratic Survival by Dictator's Military Expenditure", xlab="Years into Democracy", max_t=30)


## Figure 3.7: Military Empowerment and Coups against Democracies, 1946-2010

one <- coxph(Surv(rgjdurd, event=ulf_coup)~avbudgetpre_ulf_round+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+post90+rgjtdat+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+pres_lag+domestic8_lag+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data, x=TRUE)

plot_surv_area(time="rgjdurd", status="ulf_coup", variable="avbudgetpre_ulf_round", data=data, model=one, discrete=TRUE, bins=5, cif=T, start_color="lightgrey", end_color="black", legend.title ="Av. % of Budget", title="Coup Risk in Democracies by Dictator's Military Expenditure", xlab="Years into Democracy", max_t=30)



## Figure 3.8: Incumbent Takeovers and Civil Wars in Democracies, 1946-2010

## A: Incumbent Takeovers:

one <- coxph(Surv(rgjdurd, event=ulf_selfcoup)~avbudgetpre_ulf_round+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+post90+rgjtdat+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+pres_lag+domestic8_lag+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data, x=TRUE, iter.max=30) 

plot_surv_area(time="rgjdurd", status="ulf_selfcoup", variable="avbudgetpre_ulf_round", data=data, model=one, discrete=TRUE, bins=5, cif=T, start_color="lightgrey", end_color="black", legend.title ="Av. % of Budget", title="Self-Coup Risk in Democracies by Dictator's Military Expenditure", xlab="Years into Democracy", max_t=30)

## B: Civil Wars

one <- coxph(Surv(rgjdurd, event=civilwar)~avbudgetpre_ulf_round+log_GDP_pc_lag_std+ch_economics2_log_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+post90+rgjtdat+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+pres_lag+domestic8_lag+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data, x=TRUE, iter.max=30)

plot_surv_area(time="rgjdurd", status="civilwar", variable="avbudgetpre_ulf_round", data=data, model=one, discrete=TRUE, bins=5, cif=T, start_color="lightgrey", end_color="black", legend.title ="Av. % of Budget", title="Civil War Risk in Democracies by Dictator's Military Expenditure", xlab="Years into Democracy", max_t=30)








#################
## Interaction ##
#################

plot.eff <- function(...) {
  pp <- effects:::plot.eff(...)
  pp$x.scales$tck=c(1,0)
  pp$y.scales$tck=c(1,0)
  pp
}
environment(plot.eff) <- asNamespace("effects")
helpenv <- new.env(parent = asNamespace("effects"))
helpenv$plot.eff <- plot.eff
plot.efflist <- effects:::plot.efflist
environment(plot.efflist) <- helpenv


## Figure 3.9: Interaction of Military Legacies with Economic Recessions

one <- lm(ulf_coup~avbudgetpre_ulf_round*Recession+log_GDP_pc_lag_std+log_oil_std+log_population_std+log_primsec_std+PRTPC10+MUSPC10+post90+rgjtdat+BRITISHCOLONY+avpolitylagregion_std+couplagregion_std+pres_lag+domestic8_lag+gwf_prior_personal+gwf_prior_military+counterbalancing_pre_ulf+stacking_pre_ulf, data=data)

plot(effect("avbudgetpre_ulf_round*Recession", one, xlevels=list(Recession=c(0,1))),
     main="Which Militaries Seize Opportunities to Stage Coups?", 
     xlab="Av. % of Budget under Dictatorship", ylab="Likelihood of Coup",
     colors="black", band.colors="grey0", alternating=F)

